//改文件时对axios的二次封账
//引入axios模块
import axios from "axios";
//导入进度条的样式文件
import 'nprogress/nprogress.css'
import NProgress from "nprogress";
//创建axios对象
const mockAjax = axios.create({

    baseURL: '/mock',
    timeout: 5000,//设置超时时间
})
//3:设置请求拦截器
mockAjax.interceptors.request.use(config => {
    //启用进度条
    NProgress.start()
    return config
}, error => {

    return error
})
//设置响应拦截器
mockAjax.interceptors.response.use(
    response => {
        NProgress.done()//结束进度条
        return response.data
    },
    error => {
        NProgress.done()//结束进度条
        return Promise.reject(new Error(error.message))
    }
)
//导出ajax
export default mockAjax
